
<script type="text/html" template>
    <link rel="stylesheet" href="{{ layui.setter.base }}style/login.css?v={{ layui.admin.v }}" media="all">
</script>
<style>

    .layadmin-user-login-main {
        background: #fff;
        border-radius: 5px;
        padding: 20px 10px 15px;
    }
</style>
<div class="layadmin-user-login layadmin-user-display-show" id="LAY-user-login" style="display:none;">

    <div class="layadmin-user-login-main">
        <div class="layadmin-user-login-box layadmin-user-login-header"></div>
        <div class="layadmin-user-login-box" style="text-align:center;color:#000000;">
            <font size="5">  system </font>
        </div>
        <div class="layadmin-user-login-box layadmin-user-login-body layui-form" lay-filter="admin-login-form">
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-username" for="admin-login-form-loginAccount"></label>
                <input type="text" name="loginAccount" id="admin-login-form-loginAccount" fieldname="LoginAccount" placeholder="Please input LoginAccount" lay-verify="required"   maxlen="50" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-item">
                <label class="layadmin-user-login-icon layui-icon layui-icon-password" for="admin-login-form-loginPassword"></label>
                <input type="password" name="loginPassword" id="admin-login-form-loginPassword" fieldname="LoginPassword" placeholder="Please input LoginPassword" lay-verify="required" minlen="6" maxlen="30" autocomplete="off" class="layui-input">
            </div>
            <div class="layui-form-item">
                <button class="layui-btn layui-btn-default layui-btn-fluid" lay-submit lay-filter="admin-login-form-submit">Login</button>
            </div>

        </div>
    </div>

    <div class="layui-trans layadmin-user-login-footer">

    </div>

    <div id="ProDiv" style="display:none">
        dd
    </div>
</div>
<script src="/Scripts/src/AuthenAPI.js"></script>
<script src="/Scripts/src/lib/extend/jquery.min.js"></script>
<script>
    layui.use('reForm', function () {
        var $ = layui.$
            , reForm = layui.reForm
            , view = layui.view
            , admin = layui.admin
            , router = layui.router()
            , setter = layui.setter
            , search = router.search
            , layer = layui.layer;

        $('#admin-login-form-loginPassword').bind('keydown', function (event) {
            if (event.keyCode == 13) {
                $('[lay-filter="admin-login-form-submit"]').click();
            }
        });






        $('[lay-filter="admin-login-form-submit"]').html(admin.lang ? 'Login' : '登 录')
        reForm.initForm({
            formLay: 'admin-login-form'
            , subUrl: '/Account/Login'
            , tipOk: false
            , done: function (res) {
                debugger
                layui.data(setter.tableName, {
                    key: setter.request.tokenName
                    , value: res.data.access_token
                });
                layui.data(setter.tableName, {
                    key: 'expires_at'
                    , value: res.data.expires_at
                });
                //缓存用户信息

                localStorage.setItem("userNo", res.data.UserName);
                localStorage.setItem("userEmail", res.data.Email);
                $('#admin-login-form-loginPassword').val('');
                if (res.data.FirstLogin || res.data.ChangePassword) {

                    view.warn(res.data.ChangePassword ? (admin.lang ? 'Password has not been changed for more than 90 days. Please change it.' : '超过90天未修改密码，请修改。') : (admin.lang ? 'Please change your password for the first login.' : '首次登陆，请修改密码。'), {
                        end: function () {
                            reForm.popupForm({
                                title: admin.lang ? 'Change Password' : '修改密码'
                                , formLay: 'user-set-password-form'
                                , url: 'admin/userSetPassword'
                                , subUrl: '/Admin/updateUserPassword'
                                , initData: res.data
                                , tipOk: false

                                , verify: function (data) {
                                    if (data.newPassword == data.oldPassword)
                                        return view.warn(admin.lang ? 'The new password is the same as the old one. Please change it.' : '新密码与旧密码相同，请修改。'), false;


                                    if (data.newPassword != data.checkPassword)
                                        return view.warn(admin.lang ? 'The two passwords are inconsistent.' : '两次密码不一致。'), false;

                                }
                                , done: function (res) {
                                    view.ok(admin.lang ? 'Successful modification, please login again.' : '修改成功，请重新登录。', {
                                        time: 1000
                                        , end: function () {
                                            view.exit();
                                        }
                                    })
                                }
                                , end: function () {
                                    view.exit();
                                }
                            })
                        }
                    })
                } else {
                    window.location.href = '/views/index.html';
                    //if (res.data.project.length > 1) {
                    //    var proHtml = '<div style="padding: 20px; background-color: #F2F2F2;"><div class="layui-form-item"><label>请选择项目:</label><select id="pro"style="width: 200px;height:30px; background-color: #F2F2F2;">';
                    //    for (var i = 0; i < res.data.project.length; i++) {
                    //        proHtml += '<option value=' + res.data.project[i].projecturl + '?proId=' + res.data.project[i].projectno + '>' + res.data.project[i].projectname + '</option>';
                    //    }
                    //    proHtml += '</select> </div> </div>';
                    //    console.log(res);
                    //    layer.open({
                    //        type: 1,
                    //        area: ['400px', '200px'],
                    //        fix: false,
                    //        //不固定
                    //        maxmin: true,
                    //        shade: 0.3,
                    //        title: "请选择项目",
                    //        content: proHtml,
                    //        btn: ['确定', '取消'],
                    //        // 弹层外区域关闭
                    //        yes: function (index, layero) {
                    //            admin.req({
                    //                url: '/Account/SaveProject'
                    //                , type: 'post'
                    //                , loading: false
                    //                , tipOk: false,
                    //                data: { proId: getRequest($('#pro').find('option:selected').val()) }
                    //                , done: function (resnew) {
                    //                    if (resnew.code == 0) {
                                            
                    //                        window.location.href = $('#pro').find('option:selected').val();
                    //                    }
                                        
                    //                }
                    //            });

                    //        },
                    //        btn2: function (index, layero) {
                    //            layer.closeAll();
                    //        }
                    //    });

                    //}
                    //else {
                        //admin.req({
                        //            url: '/Account/SaveProject'
                        //            , type: 'post'
                        //            , loading: false
                        //            , tipOk: false,
                        //            data: { proId: res.data.project[0].projectno }
                        //            , done: function (resnew) {
                        //                if (resnew.code == 0) {
                        //                    debugger;
                                            
                        //                    console.log("gaodong123",resnew.data);
                        //                    window.location.href = res.data.project[0].projecturl + '?proId=' + res.data.project[0].projectno;
                        //                }
                                        
                        //            }
                        //        });
                    //}


                }
            }
        }); 
        function getRequest(stringvalue) {
        debugger;
        var url = stringvalue; //获取url中"?"符后的字串
        var theRequest = "";
            if (url.indexOf("?") != -1) {
                var str = url.substr(url.indexOf("?")+1, url.length);
            strs = str.split("=");
           
                if (strs[0] == "proId") {
                    theRequest = unescape(strs[1]);
                }
            }
            var tt=theRequest.replace("\'", "").replace("\'", "");
        return theRequest.replace("\'", "").replace("\'", "");
    }
    })</script>